import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["tenantId"];
import request from 'utils/request';
import { CPAAS_FILE } from 'utils/config';
import { parseParameters, isTenantRoleLevel } from 'utils/utils';

function uploadApiSource(param) {
  return isTenantRoleLevel() ? "".concat(param.tenantId, "/upload-configs") : "upload-configs";
}

function capacityApiSource(param) {
  return isTenantRoleLevel() ? "".concat(param.tenantId, "/capacity-configs") : "capacity-configs";
}
/**
 * 查询文件大小配置列表数据
 * @async
 * @function queryFileList
 * @param {object} params - 查询条件
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */


export function queryFileList(_x) {
  return _queryFileList.apply(this, arguments);
}
/**
 * 保存文件上传头
 * @async
 * @function saveHeader
 * @param {object} params - 请求参数
 * @param {!object} params.contentType - 文件分类
 * @param {!string} params.storageSize - 文件大小限制
 * @param {?number} params.fileFormat - 文件格式
 * @param {!string} params.storageUnit - 文件大小单位
 * @param {!string} params.uploadConfigId - uploadConfigId
 * @param {!string} params.objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _queryFileList() {
  _queryFileList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var tenantId, others, param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            tenantId = params.tenantId, others = _objectWithoutProperties(params, _excluded);
            param = parseParameters(others);
            return _context.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(capacityApiSource(params)), {
              method: 'GET',
              query: _objectSpread(_objectSpread({}, param), {}, {
                tenantId: tenantId
              })
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryFileList.apply(this, arguments);
}

export function saveHeader(_x2) {
  return _saveHeader.apply(this, arguments);
}
/**
 * 添加文件上传详细配置
 * @async
 * @function addConfigDetail
 * @param {object} params - 请求参数
 * @param {!object} params.contentType - 文件分类
 * @param {!string} params.storageSize - 文件大小限制
 * @param {?number} params.fileFormat - 文件格式
 * @param {!string} params.storageUnit - 文件大小单位
 * @returns {object} fetch Promise
 */

function _saveHeader() {
  _saveHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(capacityApiSource(params)), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _saveHeader.apply(this, arguments);
}

export function addConfigDetail(_x3) {
  return _addConfigDetail.apply(this, arguments);
}
/**
 * 编辑文件上传详细配置
 * @async
 * @function editConfigDetail
 * @param {object} params - 请求参数
 * @param {!object} params.contentType - 文件分类
 * @param {!string} params.storageSize - 文件大小限制
 * @param {?number} params.fileFormat - 文件格式
 * @param {!string} params.storageUnit - 文件大小单位
 * @param {!string} params.uploadConfigId - uploadConfigId
 * @param {!string} params.objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _addConfigDetail() {
  _addConfigDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(uploadApiSource(params)), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _addConfigDetail.apply(this, arguments);
}

export function editConfigDetail(_x4) {
  return _editConfigDetail.apply(this, arguments);
}
/**
 * 删除文件上传详细配置
 * @async
 * @function deleteConfigDetail
 * @param {object} params,uploadConfigId - 请求参数
 * @param {number} uploadConfigId - uploadConfigId
 * @returns {object} fetch Promise
 */

function _editConfigDetail() {
  _editConfigDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(uploadApiSource(params)), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _editConfigDetail.apply(this, arguments);
}

export function deleteConfigDetail(_x5) {
  return _deleteConfigDetail.apply(this, arguments);
}
/**
 * 获取上传数据详情
 * @async
 * @function getUploadDetail
 * @param {object} params,uploadConfigId - 请求参数
 */

function _deleteConfigDetail() {
  _deleteConfigDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(uploadApiSource(params)), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteConfigDetail.apply(this, arguments);
}

export function getUploadDetail(_x6) {
  return _getUploadDetail.apply(this, arguments);
}

function _getUploadDetail() {
  _getUploadDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(uploadApiSource(params), "/").concat(params.uploadConfigId), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _getUploadDetail.apply(this, arguments);
}